<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>已上传图片</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../css/main.css" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <div class="layui-col-lg12 layui-col-md12 layui-col-sm12">
            <table class="layui-table" style="text-align: center;">
                <thead>
                <tr>
                    <th style="text-align: center;">图片</th>
                    <th style="text-align: center;">操作</th>
                </tr>
                </thead>
                <tbody id="imgList"></tbody>
            </table>
        </div>
    </div>
</div>
</body>

<script src="../../libs/layui/layui.js"></script>
<script src="../../js/model.js"></script>
<script type="text/javascript">
    layui.use(['form', 'element', 'layer', 'jquery', 'upload', 'laydate', 'table'], function () {
        let $ = layui.$
        let element = layui.element;
        let layer = layui.layer;
        let form = layui.form;
        let upload = layui.upload;

        // 获取contentText
        const ctx = function () {
            let pathName = document.location.pathname;
            let index = pathName.substr(1).indexOf("/");
            let result = pathName.substr(0, index + 1);
            return result;
        }();
        // 获取enterprise
        var enterprise = JSON.parse(window.sessionStorage.getItem("enterprise"));

        //获取图片列表
        var demoListView = $('#imgList');
        $.ajax({
            url: ctx + "/ygssecs/getEnterpriseImg",
            type: "GET",
            data: {enterpriseid: enterprise.enterpriseid},
            dataType: "JSON"
        }).done(function (response) {
            var imgdata = response.data;
            var code = response.code;
            if (code == 200) {
                for (var i = 0; i < imgdata.length; i++) {
                    var tr = $(['<tr id="getimg_' + i + '">'
                        , '<td><img src="' + imgdata[i].photoname + '" alt="' + imgdata[i].photoname + '" style="height: 100px;width:100px;object-fit: contain "></td>'
                        , '<td><a class="layui-btn layui-btn-danger del" id="' + imgdata[i].photoid + '" style="font-size: 12px">删 除</a></td>'
                        , '</tr>'].join(''));
                    demoListView.append(tr);
                }
                //删除
                $(".del").bind("click", function () {
                    var photoid = $(this).attr("id");
                    layer.confirm("确定要删除吗？", function () {
                        $.ajax({
                            url: ctx + "/ygssecs/deleteEnterpriseImg",
                            type: "GET",
                            data: {photoid: photoid},
                            dataType: "JSON"
                        }).done(function (response) {
                            location.reload();
                        })
                    })
                })
            }
        }).fail(function () {
            layer.msg("请求失败", {icon: 2})
        })


    });
</script>

</html>